package gui.keyActions;

import gui.DrawPanel;
import gui.eventListener.Mouse;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import dados.Curva;
import dados.Ponto;

public class DeletingPointAction extends AbstractAction{
	
	private DrawPanel drawPanel;
	private Mouse mouse;
	
	public DeletingPointAction(DrawPanel drawPanel, Mouse mouse){
		this.drawPanel = drawPanel;
		this.mouse = mouse;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		Ponto aux = this.mouse.getSelectedPoint();
		if(aux != null){
			for (int i = 0; i < this.drawPanel.getDraw().getCurves().size(); i++) {
				Curva curveAux = this.drawPanel.getDraw().getCurves().get(i);
				for (int j = 0; j < curveAux.getControlPoints().size(); j++) {
					if(curveAux.getControlPoints().get(j).equals(aux)){
						curveAux.getControlPoints().remove(j);
						
						j = curveAux.getControlPoints().size();
						i = this.drawPanel.getDraw().getCurves().size();
						
						curveAux.setModified(true);
					}
				}
			}
		}
		drawPanel.update();
	}

}
